/*
 * SchemaGeneratorAboutBox.java
 */

package schemagenerator;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.jdesktop.application.Action;

public class SchemaGeneratorViewDictionary extends javax.swing.JDialog {

    public SchemaGeneratorViewDictionary(java.awt.Frame parent) {
        super(parent);
        initComponents();
        getRootPane().setDefaultButton(closeButton);
    }

    @Action public void closeAboutBox(){
        dispose();
    }

    @Action public String readTheme() throws FileNotFoundException, IOException{
         textArea1.setText("");
         String theme = (String) jComboBox1.getSelectedItem();
         textArea1.setEditable(false);
         InputStream f = SchemaGeneratorViewDictionary.class.getResourceAsStream("/"+theme+".txt");
         InputStreamReader rd = new InputStreamReader(f);
         BufferedReader brd = new BufferedReader(rd);
         String line = "";
         int numberLine =0;
       	 while (brd.ready()){
            line = brd.readLine()+" ";
            if(!line.equals("") && !line.equals(" ")){
        	textArea1.setSelectionStart(numberLine);
                textArea1.append(line+"\n");               
            }
            numberLine++;
        }
        brd.close();
        return theme;
       

    }
     /*
      * Created to test the readTheme return lines. See SchemaGeneratorViewDictionaryTest.java
      **/
     @Action public String readTheme2() throws FileNotFoundException, IOException{
         textArea1.setText("");
         String theme = (String) jComboBox1.getSelectedItem();
         textArea1.setEditable(false);
         InputStream f = SchemaGeneratorViewDictionary.class.getResourceAsStream("/"+theme+".txt");
         InputStreamReader rd = new InputStreamReader(f);
         BufferedReader brd = new BufferedReader(rd);
         String line = "";
         int numberLine =0;
       	 while (brd.ready()){
            line = brd.readLine()+" ";
            if(!line.equals("") && !line.equals(" ")){
        	textArea1.setSelectionStart(numberLine);
                textArea1.append(line+"\n");
                return line;
            }
            numberLine++;
        }
        brd.close();
        return line;


    }

    public java.awt.TextArea  getTextArea(){
        return textArea1;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        closeButton = new javax.swing.JButton();
        javax.swing.JLabel appDescLabel = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        textArea1 = new java.awt.TextArea();
        closeButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(schemagenerator.SchemaGenerator.class).getContext().getResourceMap(SchemaGeneratorViewDictionary.class);
        setTitle(resourceMap.getString("title")); // NOI18N
        setModal(true);
        setName("aboutBox"); // NOI18N
        setResizable(false);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(schemagenerator.SchemaGenerator.class).getContext().getActionMap(SchemaGeneratorViewDictionary.class, this);
        closeButton.setAction(actionMap.get("readTheme")); // NOI18N
        closeButton.setText(resourceMap.getString("closeButton.text")); // NOI18N
        closeButton.setName("closeButton"); // NOI18N

        appDescLabel.setText(resourceMap.getString("appDescLabel.text")); // NOI18N
        appDescLabel.setName("appDescLabel"); // NOI18N

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Businesses", "Education", "Financial", " ", " " }));
        jComboBox1.setName("jComboBox1"); // NOI18N

        textArea1.setName("textArea1"); // NOI18N

        closeButton1.setAction(actionMap.get("closeAboutBox")); // NOI18N
        closeButton1.setText(resourceMap.getString("closeButton1.text")); // NOI18N
        closeButton1.setName("closeButton1"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textArea1, javax.swing.GroupLayout.DEFAULT_SIZE, 671, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(appDescLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 314, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(41, 41, 41)
                                .addComponent(closeButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(closeButton1)
                                .addGap(86, 86, 86)))
                        .addGap(357, 357, 357))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(53, 53, 53)
                .addComponent(appDescLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(closeButton)
                    .addComponent(closeButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                .addComponent(textArea1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton closeButton;
    private javax.swing.JButton closeButton1;
    private javax.swing.JComboBox jComboBox1;
    private java.awt.TextArea textArea1;
    // End of variables declaration//GEN-END:variables
    
}
